
<style lang="less">
  .page__wrapper {
    width: 100%;
    height: 100%;
  }
</style>
<template>
  <div class="page__wrapper">
    <simple-table :table-column="tableColumn" :table-data="tableData" :table-page-info="tablePageInfo" :table-data-count="tableDataTotalCount" @page-info-change="handlePageInfoChange">
      <template slot="searchSection">
        <simple-form v-model="searchModel" :form-field="searchFormField">
          <template slot="tableOperation">
            <el-button @click="handleDataSearch">{{ $t('operation.search') }}</el-button>
            <el-button v-if="actionList.indexOf('export') >= 0" type="primary" @click="handleDataExport">{{ $t('operation.export') }}</el-button>
          </template>
        </simple-form>
      </template>
      <template slot-scope="scope" slot="uploadquarter">
        {{ $getDictLabel({type: '季度', value: scope.row.uploadquarter}) }}
      </template>
      <template slot-scope="scope" slot="companyname">
        {{ scope.row.companyname | companynameFilter(orgList)}}
      </template>
      <template slot-scope="scope" slot="uploadorganization">
        {{ scope.row.uploadorganization | companynameFilter(orgList)}}
      </template>
      <template slot-scope="scope" slot="companytype">
        {{ $getDictLabel({type: '公司性质', value: scope.row.companytype}) }}
      </template>
      <template slot-scope="scope" slot="propertytype">
        {{ $getDictLabel({type: '产权性质_多种经营', value: scope.row.propertytype}) }}
      </template>
      <template slot-scope="scope" slot="businessstatus">
        {{ $getDictLabel({type: '经营状态_多种经营', value: scope.row.businessstatus}) }}
      </template>
      <template slot-scope="scope" slot="businesstype">
        {{ $getDictLabel({type: '业务类型', value: scope.row.businesstype}) }}
      </template>
    </simple-table>
  </div>
</template>
<script>
import Axios from 'axios'
/** 混入分页信息及数据总数信息 */
import pageMixins from '@/components/base/simple-table/page-mixins'
const BASEURL = {
  list: `/Web/BizController/ajax.html?sys_method=GetList&sys_objName=V_Report_Diversified_Business`,
  getInitConfig: '/Web/SysAdmin/ajax.html?sys_method=GetInitConfig',
  getCombobox: '/Web/SysAdmin/ajax.html?sys_method=GetCombobox'
}
export default {
  name: 'diversification_basic_report',
  mixins: [pageMixins],
  components: {},
  data () {
    return {
      searchModel: {},
      tableData: [],
      actionList: [],
      sys_mid: '',
      orgList: []
    }
  },
  filters: {
    companynameFilter (value, orgList) {
      let company = orgList.find(item => {
        return item.value === value
      })
      return company ? company.text : ''
    }
  },
  computed: {
    searchFormField () {
      return [
        { prop: 'companyname', label: this.$t('balance_factory.companyname'), type: 'Select', component: { clearable: true, optionList: this.orgList } },
        { prop: 'uploadyear', label: this.$t('balance_factory.uploadyear'), type: 'Datepicker', component: { clearable: true, type: 'year', valueFormat: 'yyyy' } },
        { prop: 'uploadquarter', label: this.$t('balance_factory.uploadquarter'), type: 'Select', component: { clearable: true, optionList: this.$getDictList('季度') } },
        { slotName: 'tableOperation', col: { span: 6, style: { textAlign: 'right' } }, labelWidth: '0' }
      ]
    },
    tableColumn () {
      return [
        { prop: 'uploadorganization', label: '上报单位', slotName: 'uploadorganization', minWidth: 160, fixed: 'left' },
        { prop: 'companyname', label: '企业名称', slotName: 'companyname', width: 160 },
        { prop: 'managementlevel', label: '管理层级', width: 90 },
        { prop: 'propertytype', label: '产权性质', slotName: 'propertytype', width: 100 },
        { prop: 'equitystructure', label: '股权结构', width: 100 },
        { prop: 'businessstatus', label: '经营状态', slotName: 'businessstatus', width: 100 },
        { prop: 'businesstype', label: '业务类型', slotName: 'businesstype', width: 100 },
        { prop: 'totalassets', label: '资产总额', width: 80 },
        { label: '在职人数',
          children: [
            { prop: 'contractemployeecurrent', label: '合同化员工', width: 140 },
            { prop: 'marketemployeecurrent', label: '市场化用工', width: 100 },
            { prop: 'laboremployeecurrent', label: '劳务用工', width: 90 }
          ]
        }
      ]
    }
  },
  methods: {
    handleDataSearch () {
      let params = Object.assign({}, this.tablePageInfo, { sys_mid: this.sys_mid }, { sys_search: this.searchModel })
      let loadingFlag = this.$loading({ fullscreen: false, target: this.$el, text: this.$t('tip.systemLoading') })
      this.$axios
        .post(BASEURL.list, params)
        .then(resp => {
          this.tableData = resp.rows
          this.tableDataTotalCount = resp.total
        })
        .finally(() => {
          loadingFlag.close()
        })
    },
    handleInitData () {
      let configLoadingFlag = this.$loading({ fullscreen: false, target: this.$el, text: this.$t('tip.systemLoading') })
      this.$axios.post(BASEURL.getInitConfig)
        .then(resp => {
          this.actionList = resp.actionKeys.split(',')
          this.sys_mid = resp.mid

          /** 设置列表及涉及主数据请求参数 */
          let params = Object.assign({}, this.tablePageInfo, { sys_mid: resp.mid })
          let comboParams = { sys_json: JSON.stringify([{ ObjName: 'C_SYS_Role' }, { ObjName: 'C_SYS_Org' }]) }
          let loadingFlag = this.$loading({ fullscreen: false, target: this.$el, text: this.$t('tip.systemLoading') })

          Axios.all([
            this.$axios.post(BASEURL.getCombobox, comboParams),
            this.$axios.post(BASEURL.list, params)
          ])
            .then(Axios.spread((comboData, pageData) => {
              this.orgList = comboData.C_SYS_Org

              this.tableData = pageData.rows
              this.tableDataTotalCount = pageData.total
            }))
            .finally(() => {
              loadingFlag.close()
            })
        })
        .finally(() => {
          configLoadingFlag.close()
        })
    },
    handleDataExport () { }
  },
  mounted () {
    this.handleInitData()
  }
}
</script>
